﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DatabaseComponent;



public partial class ContactUsAR : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            bindList();
        }
    }


    /// <summary>
    /// this function will bind the list view
    /// </summary>
    private void bindList()
    {
        ContactUSDB objContactUSDB = new ContactUSDB(ConnectionStrings.LMS);
        List<ContactUS> lstContactUS = objContactUSDB.Select("", "");

        lvContactUs.DataSource = lstContactUS;
        lvContactUs.DataBind();

        if (lvContactUs.Items.Count > 0)
        {
            Control hrNew = lvContactUs.Items[lvContactUs.Items.Count - 1].FindControl("hrNew");
            hrNew.Visible = false;
        }
    }

    protected void lvContactUs_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {

            HiddenField hf = (HiddenField)e.Item.FindControl("hdID");
            
            long ContactUSID = 0;
            long.TryParse(hf.Value,out ContactUSID);

            ContactUSDB objContactUSDB = new ContactUSDB(ConnectionStrings.LMS);
            List<ContactUS> lstContactUS = objContactUSDB.getContactUSByID(ContactUSID);

            if (lstContactUS.Count == 0)
                return;

            if (lstContactUS[0].Email1 == "")
                e.Item.FindControl("dvEmail1").Visible = false;

            if (lstContactUS[0].Email2 == "")
                e.Item.FindControl("dvEmail2").Visible = false;


            if (lstContactUS[0].Phone1 == "")
                e.Item.FindControl("dvPhone1").Visible = false;

            if (lstContactUS[0].Phone2 == "")
                e.Item.FindControl("dvPhone2").Visible = false;

            if (lstContactUS[0].Mobile1 == "")
                e.Item.FindControl("dvMobile1").Visible = false;


            if (lstContactUS[0].Mobile2 == "")
                e.Item.FindControl("dvMobile2").Visible = false;

            

        }

    }
}
